import {defineStore} from 'pinia';
import workApi from "@/http/workApi";
import router from "@/router";

export const useStudentStore = defineStore('student', {
    actions: {

        updateStudentProject() {
            // 更新学生所在项目
            workApi.get('student/training').then((res) => {
                this.studentProject = res.data
            })
        },
        setMenuValue(value = "", enabled = null) {
            this.menu.value = value
            if (typeof enabled === "boolean") {
                this.menu.enabled = enabled
                if (enabled) {
                    router.push({
                        name: "StudentIndex",
                    })
                }
            }
        },
        updateQuestionBank({training_id, task_id}) {
            training_id = Number(training_id)
            task_id = Number(task_id)
            workApi.post('student/task', {
                training_id,
                task_id
            }).then(r => {
                this.questionBank = r.data
            });
        },
        setTaskState(projectId = null, taskId = null) {
            workApi.post("student/task_analysis_status", {
                "training_id": +projectId,
                "task_id": +taskId,
            }).then(r => {
                this.taskState.rating_type = r.data.rating_type || null
                this.taskState.auto_scoring = r.data.auto_scoring || false
                this.taskState.task_analysis_status = r.data.task_analysis_status || false
            })
        },
    },


    state: () => ({
        // 学生任务列表
        studentProject: [],
        // 左侧菜单
        menu: {
            value: null,
            enabled: true,
        },
        // 题库
        questionBank: {},
        // 任务状态
        taskState: {
            task_analysis_status: false,
            rating_type: null,
            auto_scoring: false,
        }

    }),

    getters: {},
})
